package com.example.test.controller;

import com.example.test.model.Course;
import com.example.test.model.Student;
import com.example.test.model.StudentCourse;
import com.example.test.service.CourseService;
import com.example.test.service.StudentCourseService;
import com.example.test.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("studentCourse")
public class StudentCourseController extends BaseController{
    private final StudentCourseService studentCourseService;
    private final StudentService studentService;
    private final CourseService courseService;

    public StudentCourseController(StudentCourseService studentCourseService, StudentService studentService, CourseService courseService) {
        this.studentCourseService = studentCourseService;
        this.studentService = studentService;
        this.courseService = courseService;
    }

    @GetMapping("queryStudentAndCourse")
    private String queryStudentAndCourse(){
      session.setAttribute("student", studentService.queryAll());
      session.setAttribute("course",courseService.queryAll());
      return "redirect:/student_course/add.jsp";
    }

    @PostMapping("create")
    private String create(StudentCourse studentCourse){
        studentCourseService.create(studentCourse);
        return "redirect:/studentCourse/queryStudentCourse";
    }

    @GetMapping("queryStudentCourse")
    private String queryStudentCourse(){
        List<StudentCourse> studentCourses = studentCourseService.queryList("queryStudentCourse",null);
        session.setAttribute("studentCourseList",studentCourses);
        return "redirect:/student_course/list.jsp";

    }
    @GetMapping("queryStudentCourses")
    private String queryStudentCourses(){
        List<Student> students = studentService.queryList("queryStudentCourses", null);
        session.setAttribute("students",students);
        return "redirect:/student_course/list2.jsp";
    }
    @GetMapping("queryCourseStudents")
    private String queryCourseStudents(){
        List<Course> courses = courseService.queryList("queryCourseStudents",null);
        session.setAttribute("courses",courses);
        return "redirect:/student_course/list3.jsp";
    }
    @GetMapping("queryStudentCoursesList")
    private String queryStudentCoursesList() {
        List<Student> studentsList = studentService.queryList("queryStudentCoursesList", null);
        session.setAttribute("studentsList", studentsList);
        return "redirect:/student_course/list4.jsp";
    }
}